﻿using DrawableObjects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GlobalGameClasses;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Audio;
using System.Collections.Generic;
using Sirian.DrawableObject;
using Serialization;


namespace SirianTestEnvironment
{
    
    
    /// <summary>
    ///Dies ist eine Testklasse für "TerrainTest" und soll
    ///alle TerrainTest Komponententests enthalten.
    ///</summary>
    [TestClass()]
    public class TerrainTest
    {
        private static Texture2D[] terrainTex;
        private static Texture2D[] heightMapTex;
        private static Terrain terrain_test;

        private TestContext testContextInstance;

        /// <summary>
        ///Ruft den Testkontext auf, der Informationen
        ///über und Funktionalität für den aktuellen Testlauf bietet, oder legt diesen fest.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Zusätzliche Testattribute
        [ClassCleanup()]
        public static void MyClassCleanup()
        {
            GlobalGameValues.Values.achievementsUnlocked = new List<Achievement>();
            GlobalGameValues.Values.content = new ContentCollection();
            GlobalGameValues.Values.difficulty = null;
            GlobalGameValues.Values.errorWriter = null;
            GlobalGameValues.Values.gameTime = new GameTime();
            GlobalGameValues.Values.GlobalStrings = new StringContainer();
            GlobalGameValues.Values.graphicsDevice = null;
            GlobalGameValues.Values.score = new InterfaceComponents.HUDWrapper<int>(new List<InterfaceComponents.HUDComponent>());
            GlobalGameValues.Values.soundPlayer = null;
            GlobalGameValues.Values.spriteBatch = null;
            GlobalGameValues.Values.volume_Music = 0;
            GlobalGameValues.Values.volume_soundEffect = 0;
        }

        /// <summary>
        /// Initializes the required attributes for the test methods of this test class.
        /// </summary>
        /// <param name="testContext"></param>
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            System.Windows.Forms.Form form = new System.Windows.Forms.Form();
            form.Visible = false;
            form.ShowInTaskbar = false;
            PresentationParameters param = new PresentationParameters();
            param.DeviceWindowHandle = form.Handle;
            param.IsFullScreen = false;
            GraphicsDevice device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, param);

            Texture2D lavaTex1;
            string filePath1 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\lavaTexture_1.jpg";
            System.IO.FileStream fs1 = new System.IO.FileStream(filePath1, System.IO.FileMode.Open);
            lavaTex1 = Texture2D.FromStream(device, fs1);

            Texture2D lavaTex2;
            string filePath2 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\lavaTexture_2.jpg";
            System.IO.FileStream fs2 = new System.IO.FileStream(filePath2, System.IO.FileMode.Open);
            lavaTex2 = Texture2D.FromStream(device, fs2);

            Texture2D lavaTex3;
            string filePath3 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\lavaTexture_3.jpg";
            System.IO.FileStream fs3 = new System.IO.FileStream(filePath3, System.IO.FileMode.Open);
            lavaTex3 = Texture2D.FromStream(device, fs3);

            Texture2D lavaTex4;
            string filePath4 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\lavaTexture_4.jpg";
            System.IO.FileStream fs4 = new System.IO.FileStream(filePath4, System.IO.FileMode.Open);
            lavaTex4 = Texture2D.FromStream(device, fs4);

            Texture2D moonTex1;
            string filePath5 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\moonTexture_1.jpg";
            System.IO.FileStream fs5 = new System.IO.FileStream(filePath5, System.IO.FileMode.Open);
            moonTex1 = Texture2D.FromStream(device, fs5);

            Texture2D moonTex2;
            string filePath6 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\moonTexture_2.png";
            System.IO.FileStream fs6 = new System.IO.FileStream(filePath6, System.IO.FileMode.Open);
            moonTex2 = Texture2D.FromStream(device, fs6);

            Texture2D moonTex3;
            string filePath7 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\moonTexture_3.jpg";
            System.IO.FileStream fs7 = new System.IO.FileStream(filePath7, System.IO.FileMode.Open);
            moonTex3 = Texture2D.FromStream(device, fs7);

            Texture2D moonTex4;
            string filePath8 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\moonTexture_4.jpg";
            System.IO.FileStream fs8 = new System.IO.FileStream(filePath8, System.IO.FileMode.Open);
            moonTex4 = Texture2D.FromStream(device, fs8);

            Texture2D sandTex1;
            string filePath9 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\sandTexture_1.jpg";
            System.IO.FileStream fs9 = new System.IO.FileStream(filePath9, System.IO.FileMode.Open);
            sandTex1 = Texture2D.FromStream(device, fs9);

            Texture2D sandTex2;
            string filePath10 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\sandTexture_2.jpg";
            System.IO.FileStream fs10 = new System.IO.FileStream(filePath10, System.IO.FileMode.Open);
            sandTex2 = Texture2D.FromStream(device, fs10);

            Texture2D sandTex3;
            string filePath11 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\sandTexture_3.jpg";
            System.IO.FileStream fs11 = new System.IO.FileStream(filePath11, System.IO.FileMode.Open);
            sandTex3 = Texture2D.FromStream(device, fs11);

            Texture2D sandTex4;
            string filePath12 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\TerrainTextures\\sandTexture_4.jpg";
            System.IO.FileStream fs12 = new System.IO.FileStream(filePath12, System.IO.FileMode.Open);
            sandTex4 = Texture2D.FromStream(device, fs12);

            Texture2D heightMapTex1;
            string filePath13 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\hm350x14336_grau-00-0.jpg";
            System.IO.FileStream fs13 = new System.IO.FileStream(filePath13, System.IO.FileMode.Open);
            heightMapTex1 = Texture2D.FromStream(device, fs13);

            Texture2D heightMapTex2;
            string filePath14 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\hm350x14336_grau-00-1.jpg";
            System.IO.FileStream fs14 = new System.IO.FileStream(filePath14, System.IO.FileMode.Open);
            heightMapTex2 = Texture2D.FromStream(device, fs14);

            Texture2D heightMapTex3;
            string filePath15 = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + "\\Out\\hm350x14336_grau-00-2.jpg";
            System.IO.FileStream fs15 = new System.IO.FileStream(filePath15, System.IO.FileMode.Open);
            heightMapTex3 = Texture2D.FromStream(device, fs15);
            
            GlobalGameValues.Values.graphicsDevice = device;

            terrainTex = new Texture2D[12];
            terrainTex[0] = lavaTex1;
            terrainTex[1] = lavaTex2;
            terrainTex[2] = lavaTex3;
            terrainTex[3] = lavaTex4;
            terrainTex[4] = moonTex1;
            terrainTex[5] = moonTex2;
            terrainTex[6] = moonTex3;
            terrainTex[7] = moonTex4;
            terrainTex[8] = sandTex1;
            terrainTex[9] = sandTex2;
            terrainTex[10] = sandTex3;
            terrainTex[11] = sandTex4;

            heightMapTex = new Texture2D[3];
            heightMapTex[0] = heightMapTex1;
            heightMapTex[1] = heightMapTex2;
            heightMapTex[2] = heightMapTex3;

            terrain_test = new Terrain(heightMapTex, terrainTex, device);




            fs1.Close();
            fs2.Close();
            fs3.Close();
            fs4.Close();
            fs5.Close();
            fs6.Close();
            fs7.Close();
            fs8.Close();
            fs9.Close();
            fs10.Close();
            fs11.Close();
            fs12.Close();
            fs13.Close();
            fs14.Close();
            fs15.Close();

        }
        
        #endregion


        /// <summary>
        ///Test for "Terrain-Constructor"
        ///</summary>
        [TestMethod()]
        public void TerrainConstructorTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            Texture2D[] heightMap = (Texture2D[])terrain.GetProperty("heightMap");
            Assert.IsNotNull(heightMap);
            Assert.AreEqual(heightMapTex.Length, heightMap.Length);
            for (int i = 0; i < heightMap.Length; i++)
            {
                Assert.AreEqual(heightMapTex[i], heightMap[i]);
            }

            Texture2D[] terrainTextures = (Texture2D[])terrain.GetProperty("terrainTextures");
            Assert.IsNotNull(terrainTextures);
            Assert.AreEqual(terrainTex.Length, terrainTextures.Length);
            for (int i = 0; i < terrainTextures.Length; i++)
            {
                Assert.AreEqual(terrainTex[i], terrainTextures[i]);
            }

            for (int i = 0;i < heightMap.Length; i++)
            {
                Assert.AreEqual(heightMap[i].Height, terrain_test.terrainHeight_part);
            }

            Assert.IsNotNull(terrain.GetField("heightData_list"));
            Assert.IsNotNull(terrain.GetField("vertices_list"));
            Assert.AreEqual(0, terrain_test.progress);
            Assert.IsNotNull(terrain.GetField("indices"));
            Assert.IsNotNull(terrain.GetField("doubleIndices"));
            Assert.IsNotNull(terrain.GetProperty("deviceIndexBuffer"));

        }

        /// <summary>
        ///Test for "CalculateNormals"
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SirianGame.exe")]
        public void CalculateNormalsTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            List<VertexTerrain[]> vertices_list = (List<VertexTerrain[]>)terrain.GetField("vertices_list");

            foreach (VertexTerrain[] verticesObject in vertices_list)
            {
                for (int i = 0; i < verticesObject.Length; i++)
                {
                    Assert.IsNotNull(verticesObject[i].normal);
                    Assert.AreNotEqual(Vector3.Zero, (Vector3)verticesObject[i].normal);
                    Assert.AreEqual(1, Math.Round((float)verticesObject[i].normal.Length()));
                }
            }
        }

        /// <summary>
        ///Test for "CopyToDeviceBuffers"
        ///</summary>
        [TestMethod()]
        public void CopyToDeviceBuffersTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            VertexTerrain[] mergedVertices = (VertexTerrain[])terrain.GetField("mergedVertices");
            List<VertexTerrain[]> vertices_list = (List<VertexTerrain[]>)terrain.GetField("vertices_list");

            Assert.IsNotNull(mergedVertices);
            Assert.AreEqual(2 * heightMapTex[0].Height * heightMapTex[0].Width, mergedVertices.Length);
            for (int i = 0; i < 2; i++)
            {
                for (int x = 0; x < heightMapTex[0].Width; x++)
                {
                    for (int y = 0; y < heightMapTex[0].Height; y++)
                    {
                        Assert.AreEqual(vertices_list[i][x + heightMapTex[0].Width * y], mergedVertices[(x + heightMapTex[0].Width * y) + i * heightMapTex[0].Width * heightMapTex[0].Height]);
                    }
                }
            }

            DynamicVertexBuffer deviceVertexBuffer = (DynamicVertexBuffer)terrain.GetProperty("deviceVertexBuffer");
            int vertexCount = deviceVertexBuffer.VertexCount;

            Assert.AreEqual(vertexCount, mergedVertices.Length);
        }

        /// <summary>
        ///Test for "CreateHeightData"
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SirianGame.exe")]
        public void CreateHeightDataTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            int terrainWidth = (int)terrain.GetProperty("terrainWidth");
            int terrainHeight = (int)terrain.GetProperty("terrainHeight");

            Assert.AreEqual(terrainWidth, heightMapTex[0].Width);
            Assert.AreEqual(terrainHeight, heightMapTex[0].Height * heightMapTex.Length);
            Assert.IsNotNull((float)terrain.GetProperty("terrainMaxHeight"));
            Assert.IsNotNull((float)terrain.GetProperty("terrainMinHeight"));
            Assert.IsTrue((float)terrain.GetProperty("terrainMinHeight") <= (float)terrain.GetProperty("terrainMaxHeight"));

            List<float[,]> heightData_list = (List<float[,]>)terrain.GetField("heightData_list");

            Assert.IsNotNull(heightData_list);
            Assert.AreEqual(heightMapTex.Length, heightData_list.Count);
        }

        /// <summary>
        ///Test for "CreateIndices"
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SirianGame.exe")]
        public void CreateIndicesTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            int width = 300;
            int height = 500;

            object[] args = new object[2];
            args[0] = width;
            args[1] = height;

            int[] indices = (int[])terrain.Invoke("CreateIndices", args);

            Assert.AreEqual((width - 1) * (height - 1) * 6, indices.Length);

            int counter = 0;
            for (int y = 0; y < height - 1; y++)
            {
                for (int x = 0; x < width - 1; x++)
                {
                    Assert.AreEqual(indices[counter++], x + (y + 1) * width);
                    Assert.AreEqual(indices[counter++], (x + 1) + y * width);
                    Assert.AreEqual(indices[counter++], x + y * width);

                    Assert.AreEqual(indices[counter++], x + (y + 1) * width);
                    Assert.AreEqual(indices[counter++], (x + 1) + (y + 1) * width);
                    Assert.AreEqual(indices[counter++], (x + 1) + y * width);

                }
            }
            
        }

        /// <summary>
        ///Test for "CreateVertices"
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SirianGame.exe")]
        public void CreateVerticesTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            List<VertexTerrain[]> vertices_list = (List<VertexTerrain[]>)terrain.GetField("vertices_list");

            Assert.IsNotNull(vertices_list);
            Assert.AreEqual(heightMapTex.Length, vertices_list.Count);

            foreach (VertexTerrain[] vertices_list_object in vertices_list)
            {
                for (int i = 0; i < vertices_list_object.Length; i++)
                {
                    Assert.IsNotNull(vertices_list_object[i].position);
                    
                    Assert.IsNotNull(vertices_list_object[i].textureCoordinate.X);
                    Assert.IsNotNull(vertices_list_object[i].textureCoordinate.Y);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsMoon.X);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMoon.X >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMoon.X <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsMoon.Y);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMoon.Y >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMoon.Y <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsMoon.Z);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMoon.Z >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMoon.Z <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsMoon.W);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMoon.W >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMoon.W <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsMars.X);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMars.X >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMars.X <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsMars.Y);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMars.Y >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMars.Y <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsMars.Z);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMars.Z >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMars.Z <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsMars.W);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMars.W >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsMars.W <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsLava.X);
                    Assert.IsTrue(vertices_list_object[i].texWeightsLava.X >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsLava.X <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsLava.Y);
                    Assert.IsTrue(vertices_list_object[i].texWeightsLava.Y >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsLava.Y <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsLava.Z);
                    Assert.IsTrue(vertices_list_object[i].texWeightsLava.Z >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsLava.Z <= 1);

                    Assert.IsNotNull(vertices_list_object[i].texWeightsLava.W);
                    Assert.IsTrue(vertices_list_object[i].texWeightsLava.W >= 0);
                    Assert.IsTrue(vertices_list_object[i].texWeightsLava.W <= 1);

                }
            }

        }

        /// <summary>
        ///Test for "GetAllHeightData"
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SirianGame.exe")]
        public void GetAllHeightDataTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            List<float[,]> heightData_list = (List<float[,]>)terrain.GetField("heightData_list");

            object[] args = new object[1];
            args[0] = heightData_list;

            float[,] heightData = (float[,])terrain.Invoke("GetAllHeightData", args);

            for (int i = 0; i < heightData_list.Count; i++)
            {
                for (int x = 0; x < heightMapTex[i].Width; x++)
                {
                    for (int y = 0; y < heightMapTex[i].Height; y++)
                    {
                        Assert.AreEqual(heightData_list[i][x, y],
                                        heightData[x, i * heightMapTex[i].Height + y]);
                    }
                }
            }
        }

        /// <summary>
        ///Test for "MergeVertices"
        ///</summary>
        [TestMethod()]
        [DeploymentItem("SirianGame.exe")]
        public void MergeVerticesTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            VertexTerrain[] mergedVertices = (VertexTerrain[])terrain.GetField("mergedVertices");
            List<VertexTerrain[]> vertices_list = (List<VertexTerrain[]>)terrain.GetField("vertices_list");

            Assert.IsNotNull(mergedVertices);
            Assert.AreEqual(2 * heightMapTex[0].Height * heightMapTex[0].Width, mergedVertices.Length);
            for (int i = 0; i < 2; i++)
            {
                for (int x = 0; x < heightMapTex[0].Width; x++)
                {
                    for (int y = 0; y < heightMapTex[0].Height; y++)
                    {
                        Assert.AreEqual(vertices_list[i][x + heightMapTex[0].Width * y], mergedVertices[(x + heightMapTex[0].Width * y) + i * heightMapTex[0].Width * heightMapTex[0].Height]);
                    }
                }
            }
        }

        /// <summary>
        ///Test for "RestartTerrain"
        ///</summary>
        [TestMethod()]
        public void RestartTerrainTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            Assert.AreEqual(0, terrain_test.progress);
            Assert.AreEqual(0, terrain_test.currentTerrainPart);
            Assert.AreEqual(1, terrain_test.nextTerrainPart);

            terrain_test.progress = 1;
            terrain_test.Update();

            Assert.AreEqual(1, terrain_test.progress);
            Assert.AreEqual(1, terrain_test.currentTerrainPart);
            Assert.AreEqual(2, terrain_test.nextTerrainPart);

            terrain_test.RestartTerrain();

            Assert.AreEqual(0, terrain_test.progress);
            Assert.AreEqual(0, terrain_test.currentTerrainPart);
            Assert.AreEqual(1, terrain_test.nextTerrainPart);
        }

        /// <summary>
        ///Test for "Update"
        ///</summary>
        [TestMethod()]
        public void UpdateTest()
        {
            terrain_test = new Terrain(heightMapTex, terrainTex, GlobalGameValues.Values.graphicsDevice);
            var terrain = new PrivateObject(terrain_test);

            Assert.AreEqual(0, terrain_test.progress);
            Assert.AreEqual(0, terrain_test.currentTerrainPart);
            Assert.AreEqual(1, terrain_test.nextTerrainPart);

            terrain_test.progress = 1;
            terrain_test.Update();

            Assert.AreEqual(1, terrain_test.progress);
            Assert.AreEqual(1, terrain_test.currentTerrainPart);
            Assert.AreEqual(2, terrain_test.nextTerrainPart);

            terrain_test.progress = heightMapTex.Length - 1;
            terrain_test.Update();

            Assert.AreEqual(heightMapTex.Length - 1, terrain_test.progress);
            Assert.AreEqual(heightMapTex.Length - 1, terrain_test.currentTerrainPart);
            Assert.AreEqual(0, terrain_test.nextTerrainPart);

            terrain_test.progress = heightMapTex.Length;
            terrain_test.Update();

            Assert.AreEqual(heightMapTex.Length, terrain_test.progress);
            Assert.AreEqual(0, terrain_test.currentTerrainPart);
            Assert.AreEqual(1, terrain_test.nextTerrainPart);

            terrain_test.progress = heightMapTex.Length + 1;
            terrain_test.Update();

            Assert.AreEqual(heightMapTex.Length + 1, terrain_test.progress);
            Assert.AreEqual(1, terrain_test.currentTerrainPart);
            Assert.AreEqual(2, terrain_test.nextTerrainPart);

        }
    }
}
